import amesu from "../../model/bot/amesu";
import func from "../../model/func";
import { taskKey } from "../../shared/interface";
import { MsgAction, Tpl_Task } from "../../shared/master/MsgAction";
import { style_default } from "../../style/default";

export default async function (data: MsgAction) {
    let d = data.data as Tpl_Task;
    let s = new style_default();
    s.setTitle(d.title);
    // let desc = '';
    for (let i = 0; i < d.taskList.length; i++) {
        const element = d.taskList[i];
        let desc = element.desc
        if(desc){
            desc = element.desc.length > 2 ? element.desc : func.getTaskDesc(element.type);
        }else{
            desc = func.getTaskDesc(element.type)
        }
        if (element.now >= element.v) {
            desc = desc.replace('N', (element.v).toString())
            s.addLine(`✅${desc}`)
        } else {
            desc = desc.replace('N', (element.v - element.now).toString())
            s.addLine(`☑️${desc}`)
        }
    }
    await s.addOne();
    if(d.desc){
        s.setline_Title('任务描述','❔')
        s.addLine(`📄${d.desc}`)
    }
    s.setline_Title('完成奖励','🎁')
    for (let i = 0; i < d.reward.length; i++) {
        const element = d.reward[i];
        s.addLine(`${element.name}X${Math.ceil(element.num)}`)
    }
    if (d.end) {
        s.addLine(`🎉任务已完成,奖励已发放`)
    }
    amesu.sendText(data.tolocation, s.end());
}